# ##############################################################################
# Copyright (c) 2025 Li Auto Inc. and its affiliates
# Licensed under the Apache License, Version 2.0(the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ##############################################################################
if(CONFIG_SIM_ETH_DRIVER)
    nuttx_add_library(sim_eth STATIC)
    set(SIM_ETHPOSIX_DIR "${CMAKE_CURRENT_LIST_DIR}/tap_posix")
    set(SIM_ETHADP_INC "${NUTTX_CHIP_ABS_DIR}/driver/eth/inc")
    if(DEFINED BOARD_NAME)
        if(${BOARD_NAME} MATCHES "A2G_TC397_5V_TFT")
            set(GENDATA_DIR "${NUTTX_APPS_DIR}/${APPS_DIR}/platform_cfg/tc397_cfg/gen_data")
        endif()
        if(${BOARD_NAME} MATCHES "E3650_DEV_KIT")
            set(GENDATA_DIR "${NUTTX_APPS_DIR}/${APPS_DIR}/platform_cfg/e3650_cfg/gen_data")
        endif()
    else()
        set(GENDATA_DIR "${NUTTX_APPS_DIR}/${APPS_DIR}/cfg_prj/gen_data")
    endif()

    set(SIM_ETH_INC
        # 类型定义相关头文件
        ${NUTTX_APPS_DIR}/components/include
        ${NUTTX_APPS_DIR}/components/include/autosar
        # veth driver头文件
        ${CMAKE_CURRENT_LIST_DIR}/inc
        # tap posix层接口头文件
        ${SIM_ETHPOSIX_DIR}
        # EthIf层头文件
        ${NUTTX_APPS_DIR}/components/communication/net_dev/eth
        ${NUTTX_APPS_DIR}/components/communication/external/lwip
        ${GENDATA_DIR}/EthIf
        ${GENDATA_DIR}/Lwip
        ${GENDATA_DIR}/Memmap
        #  工程适配头文件
        ${SIM_ETHADP_INC}
    )

    file(GLOB SIM_ETH_SOURCES
        "${CMAKE_CURRENT_SOURCE_DIR}/src/*.c"
    )

    set(SIM_ETHPOSIX_INC
        # tap posix层接口头文件
        ${SIM_ETHPOSIX_DIR}
    )

    file(GLOB SIM_ETHPOSIX_SOURCES
    "${CMAKE_CURRENT_SOURCE_DIR}/tap_posix/*.c"
    )

    target_include_directories(sim_eth PRIVATE ${SIM_ETH_INC})
    target_sources(sim_eth PRIVATE ${SIM_ETH_SOURCES})

    target_include_directories(nuttx PRIVATE ${SIM_ETHPOSIX_INC})
    target_sources(nuttx PRIVATE ${SIM_ETHPOSIX_SOURCES})

endif()